package com.ruoyi.web.controller.tool;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/amita")
public class AmitaCtrl  extends BaseController {

    @Autowired
    private JdbcTemplate jdbcTemplate;


    @GetMapping("/query/sql")
    public Object getAll(String sql){
        String mysql = "select * from ("+sql+") t limit  20";
        List<Map<String, Object>> result = jdbcTemplate.queryForList(mysql);
        return R.ok(result);
    }

    @PostMapping("/run/sql")
    public Object runSql(String sql){
        jdbcTemplate.execute(sql);
        return R.ok();
    }
}
